import java.io.*;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created by lenovo on 2017/12/31.
 */
public class Java {
    public static void main(String[] args) {
//计算出未交作业的人数
        String path="C:\\Users\\Adminitrator\\Desktop\\16信本2班Java作业一";
        int fileCount=0;
        File d=new File(path);
        File list[]=d.listFiles();
        for (int i=0;i<list.length;i++){
            if (list[i].isFile()){
                fileCount++;
            }
        }
        fileCount=41-fileCount;
        System.out.println("未交作业的人数:"+fileCount);
        Map<String,Integer> map=new HashMap<>();
        //字符流
        BufferedReader reader=null;
        try {
            reader=new BufferedReader(new FileReader(
                    "C:\\Users\\Adminitrator\\Desktop\\key.txt"));
            String stuNo=null;
            while ((stuNo=reader.readLine())!=null){
                map.put(stuNo,0);
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            try {
                reader.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        //得到某一个文件夹下面所有文件
        File file=new File("C:\\Users\\Adminitrator\\Desktop\\16信本2班Java作业一");
        File[] files=file.listFiles();
        //遍历
        for (File f:files){
            String filename=f.getName();
            String no=null;
            Matcher matcher= Pattern.compile("信本2班(\\d+)")
                    .matcher(filename);
            while (matcher.find()){
                no= matcher.group(1);
            }
            map.put(no,1);
        }
        //打印所有值为0的同学,就是没有交作业的同学
        for(Map.Entry<String,Integer>entry:map.entrySet()){
            if (entry.getValue()==0){
                System.out.println(entry.getKey());
            }
        }
    }

}


